package com.za.wbw.web.wap.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;

import com.za.wbw.model.wap.ShopInfo;
import com.za.wbw.model.wap.vo.CommentListVo;
import com.za.wbw.model.wap.vo.ProductDiscountVo;
import com.za.wbw.model.wap.vo.MemberUsingVo;
import com.za.wbw.model.wap.vo.ShopInfoVo;
import com.za.wbw.model.wap.vo.ShopListVo;
import com.za.wbw.service.wap.CommentService;
import com.za.wbw.service.wap.ProductService;
import com.za.wbw.service.wap.MemberService;
import com.za.wbw.service.wap.ShopService;
import com.za.wbw.util.BaseAction;
import com.za.wbw.util.StringUtil;

public class ShopAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	private ShopService shopService;
	private MemberService memberService;
	private ProductService productService;
	private CommentService commentService;

	// 查询商店
	public String queryShopList() throws Exception{
		String start = request.getParameter("start");
		int istart = 0;
		if(!StringUtil.isNullOrEmpty(start)){
			istart = Integer.parseInt(start);
		}
		String cityId = request.getParameter("cityId");
		int icityId = 1010;
		if(!StringUtil.isNullOrEmpty(cityId)){
			icityId = Integer.parseInt(cityId);
		}
		String typeId = request.getParameter("typeId");
		int itypeId = 1;
		if(!StringUtil.isNullOrEmpty(typeId)){
			itypeId = Integer.parseInt(typeId);
		}
		String posX = request.getParameter("posX");
		int iposX = 0;
		if(!StringUtil.isNullOrEmpty(posX)){
			iposX = Integer.parseInt(posX);
		}
		String posY = request.getParameter("posY");
		int iposY = 0;
		if(!StringUtil.isNullOrEmpty(posY)){
			iposY= Integer.parseInt(posY);
		}
		String radius = request.getParameter("radius");
		int iradius = 0;
		if(!StringUtil.isNullOrEmpty(posY)){
			iradius= Integer.parseInt(radius);
		}
		String sort = request.getParameter("sort");
		int isort = 0;
		if(!StringUtil.isNullOrEmpty(sort)){
			isort = Integer.parseInt(sort);
		}
		List<ShopListVo> list = this.getShopService().queryShopList(istart, icityId, itypeId, iposX, iposY, iradius, isort);
		int total = this.getShopService().queryShopCount(icityId, itypeId, iposX, iposY, iradius, isort);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", total);
		map.put("data", list);
		JSONArray json = JSONArray.fromObject(map);
		outPrint(json);
		return null;
	}
	// 查询商店
	public String queryShopInfo() throws Exception{
		String shopId = request.getParameter("shopId");
		int ishopId = 1;
		if(!StringUtil.isNullOrEmpty(shopId)){
			ishopId = Integer.parseInt(shopId);
		}
		// 
		Map<String, Object> map = new HashMap<String, Object>();
		// 商店信息
		ShopInfoVo shopInfo = this.getShopService().queryShopInfoById(ishopId);
		map.put("shop", shopInfo);
		// 正在吃
		int usingCount= this.getMemberService().queryMemberUsingCount(ishopId);
		map.put("using_count", usingCount);
		// 正在吃
		List<String> usingVos = this.getMemberService().queryMemberUsingList(ishopId);
		map.put("using_list", usingVos);
		// 特价菜
		List<ProductDiscountVo> discountVos = this.getProductService().queryProductDiscountList(ishopId);
		map.put("discount_list", discountVos);
		// 前5菜
		int sellCount = this.getProductService().queryProductSellCount(ishopId);
		map.put("sell_count", sellCount);
		List<String> sellVos = this.getProductService().queryProductSellList(ishopId);
		map.put("sell_list", sellVos);
		// 评论
		List<CommentListVo> commentVos = this.getCommentService().queryCommentList(ishopId);
		map.put("comment_list", commentVos);
		JSONArray json = JSONArray.fromObject(map);
		outPrint(json);
		return null;
	}
	
	public CommentService getCommentService() {
		return commentService;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}

	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public ProductService getProductService() {
		return productService;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public ShopService getShopService() {
		return shopService;
	}

	public void setShopService(ShopService shopService) {
		this.shopService = shopService;
	}
}
